﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/MainTemplate.Master" AutoEventWireup="true" CodeBehind="Product.aspx.cs" Inherits="Enterprise.Admin.Product" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <link href="../Content/Widget/fancyBox/jquery.fancybox.css" rel="stylesheet" />
    <link href="../Content/Widget/kindeditor/plugins/code/prettify.css" rel="stylesheet" />
    <link href="../Content/Widget/uploadify/uploadify.css" rel="stylesheet" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <table id="table_list"></table>
    <div id="search_product">
        <form id="search_product_form" action="Handle/GetProductListJson.aspx">
            <p>
                <label>产品分类：</label><input id="search_product_categroy_id" name="CoProductCategoryId" />
            </p>
            <p>
                <label>产品名称：</label><input type="text" name="CoName" />
            </p>
            <p>
                <label>产品型号：</label><input type="text" name="CoModel" />
            </p>
            <p>
                <label>是否推荐：</label><select name="CoIsRecommend" class="easyui-combobox">
                    <option value="">全部</option>
                    <option value="true">是</option>
                    <option value="false">否</option>
                </select>

            </p>

        </form>
    </div>
    <div id="add_product">
        <form id="add_product_form">
            <div id="add_product_tabs" style="padding: 0px; height: auto">
                <div title="基础资料">
                    <p>
                        <label>产品分类：</label><input id="add_product_categroy_id" name="CoProductCategoryId" />
                        <input id="add_cover_image_id" name="CoCoverImageId" type="hidden" value="" />
                    </p>
                    <p>
                        <label>产品名称：</label><input type="text" name="CoName" />
                    </p>
                    <p class="en-us">
                        <label>产品名称(En)：</label><input type="text" name="CoNameEn" value="" />

                    </p>
                    <p>
                        <label>产品型号：</label><input type="text" name="CoModel" />
                    </p>
                    <p class="en-us">
                        <label>产品型号(En)：</label><input type="text" name="CoModelEn" />
                    </p>
                    <p>
                        <label>是否推荐：</label><input type="checkbox" name="CoIsRecommend" value="True" />

                    </p>
                    <p>
                        <label style="height: 130px; line-height: 130px;">产品概要：</label><textarea rows="5" cols="30" name="CoSummary"></textarea>
                    </p>
                    <p class="en-us">
                        <label style="height: 130px; line-height: 130px;">产品概要(En)：</label><textarea rows="5" cols="30" name="CoSummaryEn"></textarea>
                    </p>
                </div>
                <div title="技术参数">
                    <p>
                        <label>表面处理：</label><input type="text" name="CoFinish" />

                    </p>
                    <p class="en-us">
                        <label>表面处理(En)：</label><input type="text" name="CoFinishEn" value="" />
                    </p>
                    <p>
                        <label>主要材质：</label><input type="text" name="CoMaterial" />

                    </p>
                    <p class="en-us">
                        <label>主要材质(En)：</label><input type="text" name="CoMaterialEn" value="" />
                    </p>
                    <p>
                        <label>规格尺寸：</label><input type="text" name="CoSize" />
                    </p>
                    <p>
                        <label>适合门厚：</label><input type="text" name="CoDoorThickness" />
                    </p>
                    <p>
                        <label>安装中心距：</label><input type="text" name="CoBackset" />
                    </p>
                    <p>
                        <label>适用范围：</label><input type="text" name="CoAvailableFor" />
                    </p>
                    <p>
                        <label>适用范围(En)：</label><input type="text" name="CoAvailableForEn" />
                    </p>
                    <p>
                        <label>适用标准：</label><input type="text" name="CoApplicableStndard" />
                    </p>

                </div>
                <div title="产品描述" style="height: 100%">
                    <textarea name="CoDescription" id="add_product_description"></textarea>
                </div>
                <div title="产品描述(En)" style="height: 100%" class="en-us">
                    <textarea name="CoDescriptionEn" id="add_product_description_en"></textarea>
                </div>
                <div title="图片管理">
                    <div class="image_um">
                        <input id="add_file_upload" name="file_upload" type="file" multiple="true" />
                    </div>
                    <div>
                        <ul id="add_product_image_ul" class="image_list_tt">
                        </ul>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <div id="edit_product">
        <form id="edit_product_form">
            <div id="edit_product_tabs" style="padding: 0px; height: auto">
                <div title="基础资料">
                    <p>
                        <label>产品分类：</label>
                        <input id="edit_product_categroy_id" name="CoProductCategoryId" />
                        <input id="edit_cover_image_id" name="CoCoverImageId" type="hidden" value="" />
                        <input id="edit_product_id" name="CoProductId" type="hidden" value="" />
                    </p>
                    <p>
                        <label>产品名称：</label><input type="text" name="CoName" value="" />
                    </p>
                    <p class="en-us">
                        <label>产品名称(En)</label><input type="text" name="CoNameEn" value="" />

                    </p>
                    <p>
                        <label>产品型号：</label><input type="text" name="CoModel" value="" />
                    </p>
                    <p class="en-us">
                        <label>产品型号(En)：</label><input type="text" name="CoModelEn" />
                    </p>
                    <p>
                        <label>是否推荐：</label><input type="checkbox" name="CoIsRecommend" value="True" />

                    </p>
                    <p>
                        <label style="height: 130px; line-height: 130px;">产品概要：</label><textarea rows="5" cols="30" name="CoSummary"></textarea>
                    </p>
                    <p class="en-us">
                        <label style="height: 130px; line-height: 130px;">产品概要(En)：</label><textarea rows="5" cols="30" name="CoSummaryEn"></textarea>
                    </p>
                </div>
                <div title="技术参数">
                    <p>
                        <label>表面处理：</label><input type="text" name="CoFinish" />

                    </p>
                    <p class="en-us">
                        <label>表面处理(En)：</label><input type="text" name="CoFinishEn" value="" />
                    </p>
                    <p>
                        <label>主要材质：</label><input type="text" name="CoMaterial" />

                    </p>
                    <p class="en-us">
                        <label>主要材质(En)：</label><input type="text" name="CoMaterialEn" value="" />
                    </p>
                    <p>
                        <label>规格尺寸：</label><input type="text" name="CoSize" />
                    </p>
                    <p>
                        <label>适合门厚：</label><input type="text" name="CoDoorThickness" />
                    </p>
                    <p>
                        <label>安装中心距：</label><input type="text" name="CoBackset" />
                    </p>
                    <p>
                        <label>适用范围：</label><input type="text" name="CoAvailableFor" />
                    </p>
                    <p>
                        <label>适用范围(En)：</label><input type="text" name="CoAvailableForEn" />
                    </p>
                    <p>
                        <label>适用标准：</label><input type="text" name="CoApplicableStndard" />
                    </p>

                </div>
                <div title="产品描述" style="height: 100%">
                    <textarea name="CoDescription" id="edit_product_description"></textarea>
                </div>
                <div title="产品描述(En)" style="height: 100%" class="en-us">
                    <textarea name="CoDescriptionEn" id="edit_product_description_en"></textarea>
                </div>
                <div title="图片管理">
                    <div class="image_um">
                        <input id="edit_file_upload" name="file_upload" type="file" multiple="true" />
                    </div>
                    <div>
                        <ul id="edit_product_image_ul" class="image_list_tt">
                        </ul>
                    </div>
                </div>
            </div>
        </form>
    </div>

    <script type="text/javascript">
        $(document).ready(function () {
            var tableList = $("#table_list").datagrid({
                title: '产品列表',
                fit: true,
                nowrap: false,
                autoRowHeight: false,
                striped: true,
                collapsible: true,
                url: 'Handle/GetProductListJson.aspx',
                idField: 'id',
                fitColumns: true,
                singleSelect: true,
                onLoadSuccess: function () {
                    $(".fancybox_image").fancybox({
                        'transitionIn': 'none',
                        'transitionOut': 'none',
                        'titlePosition': 'over'
                    });
                },
                onClickRow: function (rowIndex) {
                    $('#table_list').datagrid("unselectRow", rowIndex);
                },
                columns: [[
                         { title: 'Id', field: 'id', width: 280, align: 'center', checkbox: true },
                         { title: '产品名称', field: 'CoName', width: 180, align: 'center' },
                         { title: '产品名称(En)', field: 'CoNameEn', width: 180, align: 'center' },
                         { title: '类型名称', field: 'CoCategoryName', width: 180, align: 'center' },
                         {
                             field: 'CoIsRecommend', title: '推荐', width: 80, align: 'center',
                             formatter: function (value) {
                                 return value == "True" ? '是' : '否';
                             }
                         },
                        {
                            field: 'CoNormalImage', title: '图片', width: 80, align: 'center',
                            formatter: function (value, rowData) {
                                return '<a class="fancybox_image" href="../upload/product/' + rowData.CoNormalImage + '"></a>';
                            }
                        },
                       {
                           title: '修改', field: 'OpEdit', width: 80, align: 'center', formatter: function (value, rec) {
                               return '<a href="javascript:void(0);" mce_href="#" onclick="edit(\'' + rec.id + '\')">修改</a> ';
                           }
                       },
                        {
                            title: '删除', field: 'OpDelete', width: 80, align: 'center', formatter: function (value, rec) {
                                return '<a href="javascript:void(0);" mce_href="#" onclick="del(\'' + rec.id + '\')">删除</a> ';

                            }
                        }
                ]],
                pagination: true,
                rownumbers: true,
                toolbar: [{
                    text: '添加',
                    iconCls: 'icon-add',
                    handler: function () {
                        add();
                    }
                }, {
                    text: '修改',
                    iconCls: 'icon-edit',
                    handler: function () {
                        var selectData = $('#table_list').datagrid('getSelected');
                        if (selectData == null) {
                            $.messager.show({
                                title: '提示',
                                msg: '请选择要修改记录！',
                                timeout: 5000,
                                showType: 'fade'
                            });
                        } else {
                            edit(selectData.id);
                        }
                    }

                }, {
                    text: '删除',
                    iconCls: 'icon-remove',
                    handler: function () {
                        var selectData = $('#table_list').datagrid('getSelected');
                        if (selectData == null) {
                            $.messager.show({
                                title: '提示',
                                msg: '请选择要删除记录！',
                                timeout: 5000,
                                showType: 'fade'
                            });
                        } else {
                            del(selectData.id);
                        }

                    }

                }, {
                    text: '查找',
                    iconCls: 'icon-search',
                    handler: function () {
                        $('#search_product').dialog("open");
                    }

                }]
            });
            $('#add_product').dialog({
                title: '添加产品',

                width: 750,
                height: 500,
                closed: true,
                buttons: [{
                    text: '保存',
                    iconCls: 'icon-ok',
                    handler: function () {
                        addProductDescription.sync();
                        addProductDescriptionEn.sync();
                        addSave(function () { });
                    }
                }, {
                    text: '关闭',
                    handler: function () {
                        $('#add_product').dialog('close');
                    }
                }]

            });
            $('#edit_product').dialog({
                title: '修改产品',

                width: 750,
                height: 500,
                closed: true,
                buttons: [{
                    text: '保存',
                    iconCls: 'icon-ok',
                    handler: function () {
                        editProductDescription.sync();
                        editProductDescriptionEn.sync();
                        editSave();
                    }
                }, {
                    text: '关闭',
                    handler: function () {
                        $('#edit_product').dialog('close');
                    }
                }]
            });
            $('#search_product').dialog({
                title: '检索产品',
                width: 400,
                height: 250,
                closed: true,
                buttons: [{
                    text: '查找',
                    iconCls: 'icon-ok',
                    handler: function () {
                        tableList.datagrid("reload", $('#search_product_form').serializeObject());
                    }
                }, {
                    text: '关闭',
                    handler: function () {
                        $('#search_product').dialog('close');
                    }
                }]
            });
            $('#edit_product_form').form({
                onBeforeLoad: function () {
                },
                onLoadSuccess: function (data) {
                    $("#edit_product_image_ul").html('');
                    $.each(data.ProductImage, function () {
                        $("#edit_product_image_ul").append('<li><div class="img_l_l"><div class="image_fram"><img class="image_thum" src="../Upload/Product/' + this.thumFileName + '"/>   <input type="hidden" name="CoProductImageId" value="' + this.id + '"/></div></div><div class="img_l_r"><p><input class="edit_set_cover" name="edit_set_cover" ' + (this.id == data.CoCoverImageId ? 'checked="checked"' : '') + ' valuedata="' + this.id + '" type="radio"/>设置封面</p><p><a href="javascript:void(0);" class="delete_product_image" value="' + this.id + '">删除图片</a></p></div></li>');
                    });
                    editProductDescription.html(data.CoDescription);
                    editProductDescriptionEn.html(data.CoDescriptionEn);
                    $('#edit_product').dialog("open");
                },
                onLoadError: function () {

                }
            });
            $('#add_product_tabs').tabs({
                border: false
            });
            $('#edit_product_tabs').tabs({
                border: false
            });
            var addProductDescription = window.KindEditor.create('#add_product_description', {
                uploadJson: "Handle/KindEditorUploadJson.aspx",
                fileManagerJson: "Handle/KindEditorFileManagerJson.aspx",
                width: '668px',
                height: '375px',
                filterMode: false,
                allowFileManager: true,
                afterCreate: function () {

                }
            });
            var addProductDescriptionEn = window.KindEditor.create('#add_product_description_en', {
                uploadJson: "Handle/KindEditorUploadJson.aspx",
                fileManagerJson: "Handle/KindEditorFileManagerJson.aspx",
                width: '668px',
                height: '375px',
                filterMode: false,
                allowFileManager: true,
                afterCreate: function () {

                }
            });
            var editProductDescription = window.KindEditor.create('#edit_product_description', {
                uploadJson: "Handle/KindEditorUploadJson.aspx",
                fileManagerJson: "Handle/KindEditorFileManagerJson.aspx",
                width: '668px',
                height: '375px',
                filterMode: false,
                allowFileManager: true,
                afterCreate: function () {

                }
            });
            var editProductDescriptionEn = window.KindEditor.create('#edit_product_description_en', {
                uploadJson: "Handle/KindEditorUploadJson.aspx",
                fileManagerJson: "Handle/KindEditorFileManagerJson.aspx",
                width: '668px',
                height: '375px',
                filterMode: false,
                allowFileManager: true,
                afterCreate: function () {

                }
            });
            $("#add_file_upload").uploadify({
                'overrideEvents': ['onUploadSuccess'],
                'buttonText': '浏览...',
                'width': 100,
                'swf': '../Content/Widget/uploadify/uploadify.swf',
                'uploader': 'Handle/AddProductImage.aspx',
                'fileTypeExts': '*.gif; *.jpg; *.png',
                'formData': {
                    'CoProductId': '',
                    'ASPSESSID': '<%=Aspsessid%>', 'AUTHID': '<%=Auth%>'
                },
                'onUploadSuccess': function (file, data) {
                    var msg = $.parseJSON(data);
                    if (msg.state) {
                        $('#' + file.id).find('.data').html(' - 完成');
                        $("#add_product_image_ul").append('<li><div class="img_l_l"><div class="image_fram"><img class="image_thum" src="../Upload/Product/' + msg.thumFileName + '"/>   <input type="hidden" name="CoProductImageId" value="' + msg.id + '"/></div></div><div class="img_l_r"><p><input class="add_set_cover" name="add_set_cover" valuedata="' + msg.id + '" type="radio"/>设置封面</p><p><a href="javascript:void(0);" class="delete_product_image" value="' + msg.id + '">删除图片</a></p></div></li>');

                    } else {
                        $('#' + file.id).find('.data').html(' - 失败');
                        $.messager.show({
                            title: '提示',
                            msg: file.name + "上传失败\n错误:" + msg.message,
                            timeout: 5000,
                            showType: 'fade'
                        });
                    }
                }
            });

            $("#edit_file_upload").uploadify({
                'overrideEvents': ['onUploadSuccess'],
                'buttonText': '浏览...',
                'width': 100,
                'swf': '../Content/Widget/uploadify/uploadify.swf',
                'uploader': 'Handle/AddProductImage.aspx',
                'fileTypeExts': '*.gif; *.jpg; *.png',
                'formData': {
                    'CoProductId': '',
                    'ASPSESSID': '<%=Aspsessid%>', 'AUTHID': '<%=Auth%>'
                },
                'onUploadStart': function () {
                    $('#edit_file_upload').uploadify('settings', 'formData', { 'CoProductId': $('#edit_product_id').val() });
                },
                'onUploadSuccess': function (file, data) {
                    var msg = $.parseJSON(data);
                    if (msg.state) {
                        $('#' + file.id).find('.data').html(' - 完成');
                        $("#edit_product_image_ul").append('<li><div class="img_l_l"><div class="image_fram"><img class="image_thum" src="../Upload/Product/' + msg.thumFileName + '"/>   <input type="hidden" name="CoProductImageId" value="' + msg.id + '"/></div></div><div class="img_l_r"><p><input class="edit_set_cover" name="edit_set_cover" valuedata="' + msg.id + '" type="radio"/>设置封面</p><p><a href="javascript:void(0);" class="delete_product_image" value="' + msg.id + '">删除图片</a></p></div></li>');

                    } else {
                        $('#' + file.id).find('.data').html(' - 失败');
                        $.messager.show({
                            title: '提示',
                            msg: file.name + "上传失败\n错误:" + msg.message,
                            timeout: 5000,
                            showType: 'fade'
                        });
                    }
                }
            });
            $('.delete_product_image').live('click', function () {
                delImage(this);
            });
            $('.add_set_cover').live('click', function () {
                $('#add_cover_image_id').val($(this).attr('valuedata'));
            });
            $('.edit_set_cover').live('click', function () {
                $('#edit_cover_image_id').val($(this).attr('valuedata'));
            });
            $.ajax({
                type: "POST",
                url: "Handle/GetProductCategoryTreeDataJson.aspx",
                success: function (data) {
                    var searchData = data.concat();;
                    $('#add_product_categroy_id').combotree({
                        data: data
                    }); $('#edit_product_categroy_id').combotree({
                        data: data
                    });
                    searchData.unshift({ id: '', text: '全部' });
                    $('#search_product_categroy_id').combotree({
                        data: searchData
                    });
                },
                error: function () {
                    $.messager.show({
                        title: '提示',
                        msg: '删除失败！',
                        timeout: 5000,
                        showType: 'fade'
                    });
                }
            });
        });
        //获取产品详细
        function edit(id) {
            $('#edit_product_form').form('load', 'Handle/GetProductDetailJson.aspx?id=' + id);
        }
        function del(id) {
            $.messager.confirm("提示", "确认删除?", function (b) {
                if (b) {
                    $.ajax({
                        type: "POST",
                        url: "Handle/DeleteProdcut.aspx",
                        data: { id: id },
                        success: function (msg) {
                            $.messager.show({
                                title: '提示',
                                msg: msg.message,
                                timeout: 5000,
                                showType: 'fade'
                            });
                            if (msg.state)
                                $("#table_list").datagrid("reload");
                        },
                        error: function () {
                            $.messager.show({
                                title: '提示',
                                msg: '删除失败！',
                                timeout: 5000,
                                showType: 'fade'
                            });
                        }
                    });
                }
            });

        }
        function add() {
            $('#add_product').dialog("open");
        }
        //添加 保存
        function addSave() {
            $.ajax({
                type: "POST",
                url: "Handle/AddProduct.aspx",
                data: $('#add_product_form').serialize(),
                success: function (msg) {
                    $.messager.show({
                        title: '提示',
                        msg: msg.message,
                        timeout: 5000,
                        showType: 'fade'
                    });
                    if (msg.state) {
                        $("#table_list").datagrid("reload");
                        $('#add_product_form')[0].reset();
                        $('#add_product_image_ul').html('');
                    }
                },
                error: function () {
                    $.messager.show({
                        title: '提示',
                        msg: '保存失败！',
                        timeout: 5000,
                        showType: 'fade'
                    });
                }
            });
        }
        //编辑保存
        function editSave() {
            $.ajax({
                type: "POST",
                url: "Handle/EditProduct.aspx",
                data: $('#edit_product_form').serialize(),
                success: function (msg) {
                    $.messager.show({
                        title: '提示',
                        msg: msg.message,
                        timeout: 5000,
                        showType: 'fade'
                    });
                    if (msg.state)
                        $("#table_list").datagrid("reload");
                },
                error: function () {
                    $.messager.show({
                        title: '提示',
                        msg: '保存失败！',
                        timeout: 5000,
                        showType: 'fade'
                    });
                }
            });
        }
        //删除图片
        function delImage(th) {
            $.ajax({
                type: "POST",
                url: "Handle/DeleteProductImage.aspx",
                data: { id: $(th).attr('value') },
                context: $(th),
                success: function (msg) {
                    $.messager.show({
                        title: '提示',
                        msg: msg.message,
                        timeout: 5000,
                        showType: 'fade'
                    });
                    if (msg.state)
                        $(th).parentsUntil('li').parent().remove();
                },
                error: function () {
                    $.messager.show({
                        title: '提示',
                        msg: '删除失败！',
                        timeout: 5000,
                        showType: 'fade'
                    });
                }
            });
        }

    </script>
    <script src="../Content/Widget/fancyBox/jquery.fancybox.pack.js" type="text/javascript" charset="utf-8"></script>
    <script src="../Content/Widget/fancyBox/jquery.mousewheel.pack.js" type="text/javascript" charset="utf-8"></script>
    <script src="../Content/Widget/fancyBox/jquery.easing.pack.js" type="text/javascript" charset="utf-8"></script>
    <script src="../Content/Widget/kindeditor/kindeditor-min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../Content/Widget/kindeditor/lang/zh_CN.js" type="text/javascript" charset="utf-8"></script>
    <script src="../Content/Widget/kindeditor/plugins/code/prettify.js" type="text/javascript" charset="utf-8"></script>
    <script src="../Content/Widget/uploadify/jquery.uploadify.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../Content/Widget/jquery.json.min.js" type="text/javascript" charset="utf-8"></script>
</asp:Content>
